<?php

class Admin_StudentController extends ExtLb_Controller_Action
{
	private $studentTbl;
	private $lopTbl;
	private $managerTbl;
	
	private $studentForm;

    public function init()
    {
    	$this->loadLayout('admin','layout');
    	$this->loadCss('admin', 'student');
    	
    	$this->studentTbl	= new Admin_Model_Student();
    	$this->lopTbl		= new Admin_Model_Lops();
    	$this->managerTbl	= new Admin_Model_Manages();
    	
    }

    public function indexAction()
    {
    	$role =Zend_Auth::getInstance()->getIdentity();
    	
    	if(isset($_GET['lop'])){
    		$lop = $this->lopTbl->fetch($_GET['lop']);
    		
    		$this->view->titleViewContent	= "Danh sách sinh viên lớp ".$lop['tenLop'];
    		
	    	//
    		// === If khong phai la admin (giaovien)
    		
    		if( $role->quyen != "admin"){
    			$studentSelect = $this->studentTbl->selectStudent("idLop = '".trim($_GET['lop'])."' and u.username ='".$role->username."'");
    		}else{
    			$studentSelect = $this->studentTbl->selectStudent("idLop = '".trim($_GET['lop'])."'");
    		}	
    	}else {
    		if( $role->quyen != "admin"){
    			$studentSelect = $this->studentTbl->selectStudent("u.username ='".$role->username."'");	
    		}else{
    			$studentSelect = $this->studentTbl->selectStudent();	
    		}
    		
    	}
    	
    	$paginatorStudents	= new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($studentSelect));
    	$paginatorStudents->setItemCountPerPage(20)
       					->setPageRange(3)
       					->setCurrentPageNumber($this->_getParam('page',1));
       					
       				
       $this->view->paginatorStudents	= $paginatorStudents;
       
    }

    public function addAction()
    {
        // action body
    }

    public function deleteAction()
    {
        if (!empty($_GET['username'])){
        	$this->studentTbl->deleteStudent($_GET['username']);
        	
        	$this->jShowMessage("Đã xóa!!!");
        }
        $this->_forward("index","student","admin");
        
    }

    public function editAction()
    {
        // action body
    }


}









